package com.atguigu.netty.inboundhandlerlearndoutboundhandler;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.EventExecutorGroup;

import java.nio.charset.Charset;

/**
 * @author: 叶子
 * @date: 2022/03/30 20:17
 **/
public class MyClientHandler extends SimpleChannelInboundHandler<Long> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Long msg) throws Exception {
        System.out.println("服务器的ip="+ctx.channel().remoteAddress());
        System.out.println("收到服务器消息="+msg);
    }
//    重写channelActive 发送数据

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("MyClientHandler发送数据");
//        ctx.writeAndFlush(Unpooled.copiedBuffer(""));
        ctx.writeAndFlush(123456L);//发送的是一个long
//        ctx.writeAndFlush(Unpooled.copiedBuffer("abcdabcdabcdabcd", CharsetUtil.UTF_8));
        /**
         * 1."abcdabcdabcdabcd"是16个字节
         * 2.该处理器的前一个handler是MyLongToByteEncoder
         * 3.MyLongToByteEncoder 父类是MessageToByteEncoder
         * 4.父类 MessageToByteEncoder
         */
    }
}